package com.ssl.tensquare.base.controller;

import com.ssl.tensquare.base.pojo.Label;
import com.ssl.tensquare.base.service.LabelService;
import com.ssl.tensquare.common.entity.Result;
import com.ssl.tensquare.common.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 描述：
 *
 * @author ssl
 * @create 2019/06/06 14:29
 */
@RestController
@RequestMapping("label")
public class LabelController {
    @Autowired
    private LabelService labelService;

    /**
     * 查詢所有
     *
     * @return
     */
    @GetMapping
    public Result findAll() {
        return new Result(true, StatusCode.OK, "查询成功", labelService.findAll());
    }

    @PostMapping(value = "search/{page}/{size}")
    public Result findSearch(@RequestBody Label label, @PathVariable("page") int page,
                             @PathVariable("size") int size) {
        return new Result(true, StatusCode.OK, "查询成功", labelService.findSearch(label, page, size));
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public Result findById(@PathVariable("id") String id) {
        return new Result(true, StatusCode.OK, "查询成功", labelService.findById(id));
    }

    /**
     * 新增
     *
     * @param label
     * @return
     */
    @PostMapping
    public Result add(@RequestBody Label label) {
        labelService.add(label);
        return new Result(true, StatusCode.OK, "新增成功");
    }

    /**
     * 修改
     *
     * @param id
     * @param label
     * @return
     */
    @PutMapping("{id}")
    public Result update(@PathVariable("id") String id, @RequestBody Label label) {
        label.setId(id);
        labelService.update(label);
        return new Result(true, StatusCode.OK, "修改成功");
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable("id") String id) {
        labelService.deleteById(id);
        return new Result(true, StatusCode.OK, "删除成功");
    }


}
